﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ccit.Utils;
using Ccit.ClassLibrary;

namespace Ccit.SysPlat.Organ
{
    /// <summary>
    /// Description: 系统平台组织机构 -> 职位管理业务层
    /// Author: tim 2010-02-23
    /// </summary>
    public class PosBLL
    {
        #region initialize 

        IPos _posProcessor = null;

        public PosBLL()
        {
            _posProcessor = Factory.CreateObject(MsPos.assemblyName, MsPos.className, ImportComponentType.DotNetDll, null) as IPos;
        }

        public void Release()
        {
            _posProcessor = null;
        }
        #endregion


        /// <summary>
        /// 获取机构下的职位记录名-值对儿字典集合
        /// </summary>
        /// <param name="organId">机构Id</param>
        /// <param name="filterPosIds">过滤掉的职位记录Id串</param>        
        /// <returns></returns>
        public List<MsKeyValue> GetPosListByOrgan(string organId, string filterPosIds)
        {
            if (string.IsNullOrEmpty(organId)) return new List<MsKeyValue>();

            return _posProcessor.GetPosListByOrgan(organId, filterPosIds, string.Empty);
        }

        /// <summary>
        /// 获取职位消息对象
        /// </summary>
        /// <param name="posId">职位Id</param>
        /// <returns></returns>
        public MsPos GetPosInfo(string posId)
        {
            if (string.IsNullOrEmpty(posId)) return null;

            MsPos msPos = _posProcessor.GetPosInfo(posId);
            return msPos;
        }

        /// <summary>
        /// 保存职位信息
        /// </summary>
        /// <param name="msPos">职位信息消息对象</param>
        /// <returns>
        ///     【0】: 操作结果
        ///     【1】: 操作提示
        /// </returns>
        public List<string> Save(MsPos msPos)
        {
            if (null == msPos) return new List<string> { "-999", "操作失败:缺少必要参数!" };

            List<string> lstResult = _posProcessor.Save(msPos);
            return lstResult;
        }


        /// <summary>
        /// 职位名称同名校验
        /// </summary>
        /// <param name="posName">职位名称</param>
        /// <param name="posId">职位Id</param>
        /// <returns></returns>
        public List<string> IsExistPosName(string posName, string posId,string organId)
        {
            if (string.IsNullOrEmpty(posName)) return new List<string> { "ERROR", "校验失败:缺少必要参数!" };

            List<string> lstResult = _posProcessor.IsExistPosName(posId, posName, organId);
            return lstResult;
        }

        /// <summary>
        /// 删除职位记录
        /// </summary>
        /// <param name="posId">职位Id</param>
        /// <returns>
        ///     【0】: 操作结果
        ///     【1】: 操作提示
        /// </returns>
        public List<string> Delete(string posId)
        {
            if (string.IsNullOrEmpty(posId)) return new List<string> { "-999", "操作失败:缺少必要参数!" };
            List<string> lstResult = _posProcessor.Delete(posId);
            return lstResult;
        }
    }
}
